#!/usr/bin/python
import psycopg2
import pprint

print psycopg2.__version__
print " import success "
conn = psycopg2.connect(database='logistics',host='localhost',user='postgres',password='postgres')
c=conn.cursor()

deviceid="234234"
state=0
print "select the posNo"
sql = "select * from task where state = %s and \"posNo\" = %s;"
c.execute(sql,(state,deviceid,))
records = c.fetchall()
str=''
for item in records:
    for subitem in item:
        print subitem
        if type(subitem) != type(1):
            subitem_str=subitem.strip()
            str = str + subitem_str + '`'
#pprint.pprint(records)
u_str=str.decode('utf-8')
print 'type is ',type(u_str)

header = '1001' + 'fdsaf'
header = header.encode('utf-16-le')
c_str= u_str.encode('utf-16-le')
allstr= header + c_str
print allstr
